package com.ymatou.iapi.refund.testcase;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.optrade.resp.TradingServiceResp;
import com.ymatou.iapi.refund.parameter.CreateReturnBillBean;
import com.ymatou.iapi.refund.parameter.UserIsExistsUnFinishedRefundBean;
import com.ymatou.iapi.refund.service.CreateReturnBillCall;
import com.ymatou.iapi.refund.service.UserIsExistsUnFinishedRefundCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.RefundCallService;
import com.ymttest.business.service.YMTTrading.TradingPlaceOrderCallService;
import com.ymttest.database.model.CS_ReturnApplyBill;
import com.ymttest.database.sqlwapper.CS_ReturnApplyBillWapper;
import com.ymttest.utils.TestDataManager;
/**
*获取用户是否存在未结束的退单
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UserIsExistsUnFinishedRefund{
	private static UserIsExistsUnFinishedRefundBean bean;
	private static UserIsExistsUnFinishedRefundCall call;
	private CS_ReturnApplyBillWapper returnWapper=new CS_ReturnApplyBillWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取用户是否存在未结束的退单");
	}

	@Before
	public void caseUp() {
		bean=new UserIsExistsUnFinishedRefundBean();
		call=new UserIsExistsUnFinishedRefundCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_userIsExistsUnFinishedRefund_001() {
		Logger.start(true,"获取用户是否存在未结束的退单-验证存在,买家发起,Action=1");
		try {
			//创建一个订单
			TradingPlaceOrderCallService tradingService = new TradingPlaceOrderCallService();
			RefundCallService service = new RefundCallService();
			TradingServiceResp tradingServiceResp = tradingService
					.placeOrderWithLuxury(false);

			CreateReturnBillBean createReturnBillBean=service.setCreateReturnBillBean_AcceptOrder(tradingServiceResp,tradingService,false);
			Thread.sleep(5000);
			service.callCreateReturnBill(createReturnBillBean,new CreateReturnBillCall());
			
			bean.setUserId(createReturnBillBean.getUserid());
			call.setData(bean);
			call.callService();			
			
	        Logger.verifyEquals("true", new JSONObject(new JSONObject(call.getReturnData()).get("RetData").toString()).get("exists").toString(), "验证exists返回true");
	        Logger.verifyEquals("0", new JSONObject(new JSONObject(call.getReturnData()).get("RetData").toString()).get("errorCode").toString(), "验证errorCode返回0");
	        Logger.verifyEquals("200", call.getString("Status").toString(), "验证Status返回200");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_userIsExistsUnFinishedRefund_002() {
		Logger.start(true,"获取用户是否存在未结束的退单-验证存在，买手拒绝申请,Action=2");
		try {
			//创建一个订单
			TradingPlaceOrderCallService tradingService = new TradingPlaceOrderCallService();
			RefundCallService service = new RefundCallService();
			TradingServiceResp tradingServiceResp = tradingService
					.placeOrderWithLuxury(false);

			CreateReturnBillBean createReturnBillBean=service.setCreateReturnBillBean_AcceptOrder(tradingServiceResp,tradingService,false);
			Thread.sleep(5000);
			CreateReturnBillCall createReturnBillCall=service.callCreateReturnBill(createReturnBillBean,new CreateReturnBillCall());
			String returnId=createReturnBillCall.getCallData().getReturnBillList().get(0).getReturnId();
			int userId= TestDataManager.getRandomIntNum(5);
			//1 修改当前退货单的action
			returnWapper.updateBuyerIdByReturnId(returnId, userId,2);
			
			bean.setUserId(userId);
			call.setData(bean);
			call.callService();			
			
	        Logger.verifyEquals("true", new JSONObject(new JSONObject(call.getReturnData()).get("RetData").toString()).get("exists").toString(), "验证exists返回true");
	        Logger.verifyEquals("0", new JSONObject(new JSONObject(call.getReturnData()).get("RetData").toString()).get("errorCode").toString(), "验证errorCode返回0");
	        Logger.verifyEquals("200", call.getString("Status").toString(), "验证Status返回200");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_userIsExistsUnFinishedRefund_003() {
		Logger.start(true,"获取用户是否存在未结束的退单-验证存在，洋管家介入受理,Action=3");
		try {
			//创建一个订单
			TradingPlaceOrderCallService tradingService = new TradingPlaceOrderCallService();
			RefundCallService service = new RefundCallService();
			TradingServiceResp tradingServiceResp = tradingService
					.placeOrderWithLuxury(false);

			CreateReturnBillBean createReturnBillBean=service.setCreateReturnBillBean_AcceptOrder(tradingServiceResp,tradingService,false);
			Thread.sleep(5000);
			CreateReturnBillCall createReturnBillCall=service.callCreateReturnBill(createReturnBillBean,new CreateReturnBillCall());

			String returnId=createReturnBillCall.getCallData().getReturnBillList().get(0).getReturnId();
			int userId= TestDataManager.getRandomIntNum(5);
			//1 修改当前退货单的action
			returnWapper.updateBuyerIdByReturnId(returnId, userId,3);
			
			bean.setUserId(userId);
			call.setData(bean);
			call.callService();			
			
	        Logger.verifyEquals("true", new JSONObject(new JSONObject(call.getReturnData()).get("RetData").toString()).get("exists").toString(), "验证exists返回true");
	        Logger.verifyEquals("0", new JSONObject(new JSONObject(call.getReturnData()).get("RetData").toString()).get("errorCode").toString(), "验证errorCode返回0");
	        Logger.verifyEquals("200", call.getString("Status").toString(), "验证Status返回200");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_userIsExistsUnFinishedRefund_004() {
		Logger.start(true,"获取用户是否存在未结束的退单-验证不存在,洋管家审核拒绝,Action=4");
		try {
			//创建一个订单
			TradingPlaceOrderCallService tradingService = new TradingPlaceOrderCallService();
			RefundCallService service = new RefundCallService();
			TradingServiceResp tradingServiceResp = tradingService
					.placeOrderWithLuxury(false);

			CreateReturnBillBean createReturnBillBean=service.setCreateReturnBillBean_AcceptOrder(tradingServiceResp,tradingService,false);
			Thread.sleep(5000);
			CreateReturnBillCall createReturnBillCall=service.callCreateReturnBill(createReturnBillBean,new CreateReturnBillCall());
			
			String returnId=createReturnBillCall.getCallData().getReturnBillList().get(0).getReturnId();
			int userId= TestDataManager.getRandomIntNum(5);
			//1 修改当前退货单的action
			returnWapper.updateBuyerIdByReturnId(returnId, userId,4);
			
			bean.setUserId(userId);
			call.setData(bean);
			call.callService();			
			
	        Logger.verifyEquals("false", new JSONObject(new JSONObject(call.getReturnData()).get("RetData").toString()).get("exists").toString(), "验证exists返回true");
	        Logger.verifyEquals("0", new JSONObject(new JSONObject(call.getReturnData()).get("RetData").toString()).get("errorCode").toString(), "验证errorCode返回0");
	        Logger.verifyEquals("200", call.getString("Status").toString(), "验证Status返回200");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_userIsExistsUnFinishedRefund_005() {
		Logger.start(true,"获取用户是否存在未结束的退单-验证不存在,退货退款完成,Action=20");
		try {
			//创建一个订单
			TradingPlaceOrderCallService tradingService = new TradingPlaceOrderCallService();
			RefundCallService service = new RefundCallService();
			TradingServiceResp tradingServiceResp = tradingService
					.placeOrderWithLuxury(false);

			CreateReturnBillBean createReturnBillBean=service.setCreateReturnBillBean_AcceptOrder(tradingServiceResp,tradingService,false);
			Thread.sleep(5000);
			CreateReturnBillCall createReturnBillCall=service.callCreateReturnBill(createReturnBillBean,new CreateReturnBillCall());
			
			String returnId=createReturnBillCall.getCallData().getReturnBillList().get(0).getReturnId();
			int userId= TestDataManager.getRandomIntNum(5);
			//1 修改当前退货单的action
			returnWapper.updateBuyerIdByReturnId(returnId, userId,20);
			
			bean.setUserId(userId);
			call.setData(bean);
			call.callService();			
			
	        Logger.verifyEquals("false", new JSONObject(new JSONObject(call.getReturnData()).get("RetData").toString()).get("exists").toString(), "验证exists返回true");
	        Logger.verifyEquals("0", new JSONObject(new JSONObject(call.getReturnData()).get("RetData").toString()).get("errorCode").toString(), "验证errorCode返回0");
	        Logger.verifyEquals("200", call.getString("Status").toString(), "验证Status返回200");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_userIsExistsUnFinishedRefund_006() {
		Logger.start(true,"获取用户是否存在未结束的退单-验证不存在,退单关闭,Action=99");
		try {
			//创建一个订单
			TradingPlaceOrderCallService tradingService = new TradingPlaceOrderCallService();
			RefundCallService service = new RefundCallService();
			TradingServiceResp tradingServiceResp = tradingService
					.placeOrderWithLuxury(false);

			CreateReturnBillBean createReturnBillBean=service.setCreateReturnBillBean_AcceptOrder(tradingServiceResp,tradingService,false);
			Thread.sleep(5000);
			CreateReturnBillCall createReturnBillCall=service.callCreateReturnBill(createReturnBillBean,new CreateReturnBillCall());
			
			String returnId=createReturnBillCall.getCallData().getReturnBillList().get(0).getReturnId();
			int userId= TestDataManager.getRandomIntNum(5);
			//1 修改当前退货单的action
			returnWapper.updateBuyerIdByReturnId(returnId, userId,99);
			
			bean.setUserId(userId);
			call.setData(bean);
			call.callService();			
			
	        Logger.verifyEquals("false", new JSONObject(new JSONObject(call.getReturnData()).get("RetData").toString()).get("exists").toString(), "验证exists返回true");
	        Logger.verifyEquals("0", new JSONObject(new JSONObject(call.getReturnData()).get("RetData").toString()).get("errorCode").toString(), "验证errorCode返回0");
	        Logger.verifyEquals("200", call.getString("Status").toString(), "验证Status返回200");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_userIsExistsUnFinishedRefund_007() {
		Logger.start(true,"获取用户是否存在未结束的退单-验证不存在,退货拒收,Action=21");
		try {
			//创建一个订单
			TradingPlaceOrderCallService tradingService = new TradingPlaceOrderCallService();
			RefundCallService service = new RefundCallService();
			TradingServiceResp tradingServiceResp = tradingService
					.placeOrderWithLuxury(false);

			CreateReturnBillBean createReturnBillBean=service.setCreateReturnBillBean_AcceptOrder(tradingServiceResp,tradingService,false);
			Thread.sleep(5000);
			CreateReturnBillCall createReturnBillCall=service.callCreateReturnBill(createReturnBillBean,new CreateReturnBillCall());
			
			String returnId=createReturnBillCall.getCallData().getReturnBillList().get(0).getReturnId();
			CS_ReturnApplyBill returnBill=returnWapper.selectByApplyBillId(returnId).get(0);
			returnBill.setAccepterType(1);
			returnWapper.updateByPrimaryKey(returnBill);
			int userId= TestDataManager.getRandomIntNum(5);
			//1 修改当前退货单的action
			returnWapper.updateBuyerIdByReturnId(returnId, userId,21);
			
			bean.setUserId(userId);
			call.setData(bean);
			call.callService();			
			
	        Logger.verifyEquals("false", new JSONObject(new JSONObject(call.getReturnData()).get("RetData").toString()).get("exists").toString(), "验证exists返回true");
	        Logger.verifyEquals("0", new JSONObject(new JSONObject(call.getReturnData()).get("RetData").toString()).get("errorCode").toString(), "验证errorCode返回0");
	        Logger.verifyEquals("200", call.getString("Status").toString(), "验证Status返回200");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_userIsExistsUnFinishedRefund_008() {
		Logger.start(true,"获取用户是否存在未结束的退单-验证存在,买手退货拒收,,Action=21,AccepterType=0");
		try {
			//创建一个订单
			TradingPlaceOrderCallService tradingService = new TradingPlaceOrderCallService();
			RefundCallService service = new RefundCallService();
			TradingServiceResp tradingServiceResp = tradingService
					.placeOrderWithLuxury(false);

			CreateReturnBillBean createReturnBillBean=service.setCreateReturnBillBean_AcceptOrder(tradingServiceResp,tradingService,false);
			Thread.sleep(5000);
			CreateReturnBillCall createReturnBillCall=service.callCreateReturnBill(createReturnBillBean,new CreateReturnBillCall());
			
			String returnId=createReturnBillCall.getCallData().getReturnBillList().get(0).getReturnId();
			int userId= TestDataManager.getRandomIntNum(5);
			//1 修改当前退货单的action
			returnWapper.updateBuyerIdByReturnId(returnId, userId,21);
			
			bean.setUserId(userId);
			call.setData(bean);
			call.callService();			
			
	        Logger.verifyEquals("true", new JSONObject(new JSONObject(call.getReturnData()).get("RetData").toString()).get("exists").toString(), "验证exists返回false");
	        Logger.verifyEquals("0", new JSONObject(new JSONObject(call.getReturnData()).get("RetData").toString()).get("errorCode").toString(), "验证errorCode返回0");
	        Logger.verifyEquals("200", call.getString("Status").toString(), "验证Status返回200");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}